home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
Documents
/
Other
/
KBNS.verification.32.1
/
KBNS.11.3.011
/
DOLeakTest_main.m
next >
Wrap
Text File
|
1993-08-25
|
3KB
|
105 lines
/*
* Distributed Objects memory leak test program.
*
* To use this program, first compile it as follows:
*
* cc -Wall -g DOLeakTest_main.m -lMallocDebug -o DOLeakTest_Main
*
* To run the program, start the first one with the FULL path
* name in a shell. This becomes the server.
*
* Select this "server" from the MallocDebug.app and check for
* leaks, by clicking the "Leaks" button. It should say "No nodes"
* at this point.
*
* Now, start another one. This
* will be the client which will send the argument string over
* to the server. At this point, no leaks should occur. The next time
* you send a string, the previous string will become the leaked memory.
*
* Somebody please test this code under NEXTSTEP 3.0 and NEXTSTEP 3.1 to
* see if this BUG has been fixed under 3.1.
*
* Thanks.
*/
#import <objc/objc.h>
#import <objc/Object.h>
#import <remote/NXProxy.h>
#import <remote/NXConnection.h>
#import <stdio.h>
#import <string.h>
#define RO_NAME "leak_test"
@protocol ServerProtocol
- receiveStr:(const char *)aStr;
@end
@interface MyServer:Object {}
- receiveStr:(const char *)aStr;
@end
@implementation MyServer:Object
- receiveStr:(const char *)aStr;
{
fprintf(stderr, "Received '%s'\nThis will not be freed when '%s'"
"method returns.\nResults in a %lu octet leak the next time"
" this method is called.\n\n", aStr, sel_getName(_cmd),
(strlen(aStr) +1));
// According to NeXT Developer Docs, General Reference, Chapter 6
// Distributed Objects:
//
// "On the server side, space for the data is allocated, and a pointer to
// the local data is received. The server's allocated copy of the data is
// local in scope and will be freed by the system when the server's method
// returns."
//
// As of NEXSTSTEP 3.0, this does NOT seem to be the case, so we will
// explicitely free the data here:
// Uncomment the next line to fix the memory leak in 3.0
// free((char *)aStr); //??? This should NOT be required, but is...
return self;
}
void main(int argc, char **argv)
{
MyServer *server;
char buffer[2048];
id roserver = [NXConnection connectToName:RO_NAME];
char *str;
if (roserver)
{
[roserver setProtocolForProxy:@protocol(ServerProtocol)];
fprintf(stderr, "Connected to server\n");
fprintf(stderr, "Enter text to send (q to quit):\n");
while (str = gets(buffer))
{
if ((strlen(str) == 1) && (str[0] == 'q')) break;
[roserver receiveStr:str];
fprintf(stderr, "Sent '%s' to server\n\n", str);
fprintf(stderr, "Enter text to send:\n");
}
} else {
server = [[MyServer alloc] init];
roserver = [NXConnection registerRoot:server withName:RO_NAME];
fprintf(stderr, "Server waiting to receive strings...\n\n");
[roserver run];
}
exit(0);
}